package com.kkb.merchant.center.controller;


import com.kkb.merchant.center.api.RoleInfoService;
import com.kkb.merchant.center.api.UserInfoService;
import com.kkb.merchant.center.common.pojo.RoleInfo;
import com.kkb.merchant.center.common.pojo.UserInfo;
import com.kkb.merchant.center.common.util.SecurityUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/auth")
public class AuthController {

    @Reference
    private UserInfoService userInfoService;

    @Reference
    private RoleInfoService roleInfoService;

    @GetMapping(value = "/info/{type}")
    public ResponseEntity<Object> getUserInfo(@PathVariable Integer type){
        UserInfo userInfo = userInfoService.findByUserName(SecurityUtils.getUserName());
        List<RoleInfo> roleInfos = roleInfoService.selectRoleByUserId(userInfo.getId());

        userInfo.setRoleList(roleInfos);

        return ResponseEntity.ok(userInfo);
    }
}
